package face.array;

import java.util.Arrays;

/**
 * @author spf
 * @date 2024/8/13
 * @time 21:56
 */

/**
 * 移除元素
 */
public class RemoveElement {

    public static void main(String[] args){
        int[] a={1,2,3,4,5,6,7,8,9,10};
        int i = removeElement(a, 2);
        System.out.println(Arrays.toString(a));
        System.out.println(i);

    }

    private static int removeElement(int[] nums, int val) {
        int i = 0;
        for(int j=0; j< nums.length; j++){
            if (nums[j] != val){
                nums[i++] = nums[j];
            }
        }
        return i;
    }

}
